<!DOCTYPE html>
<html lang="en">
<head>
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <title>添加文章分类页面</title>
    <link rel="stylesheet" href="__PUBLIC__/static/common/layui/css/layui.css"  media="all">
</head>
<style>
</style>
<body style="background-color: #fff;">
<fieldset class="layui-elem-field layui-field-title" style="margin-top: 10px; ">
    <legend style="font-size: 14px;">添加文章分类</legend>
</fieldset>

    <div class="layui-field-box">
        <form method="post" class="layui-form">
            <div class="layui-form-item">
                <label class="layui-form-label">分类名称</label>
                <div class="layui-input-block">
                    <input  type="text" name="title" lay-verify="title"  autocomplete="off" placeholder="请输入分类名称" class="layui-input">
                </div>
            </div>


            {notempty name="article_type"}
                <div class="layui-form-item">
                    <label class="layui-form-label">父类文章类别</label>
                    <div class="layui-input-block">
                        <input type="text"  value="{$article_type.id}" name="pid"   autocomplete="off" class="layui-input"  style="display: none" >
                        <input type="text"  value="{$article_type.title}"  autocomplete="off" class="layui-input"  readonly="readonly">
                    </div>
                    </div>
            {/notempty}


            <div class="layui-form-item">
                <label class="layui-form-label">分类排序</label>
                <div class="layui-input-block">
                    <input type="text" name="sort" value=""  placeholder="分类排序"  autocomplete="off" class="layui-input">
                </div>
            </div>


            <div class="layui-form-item layui-form-text">
                <label class="layui-form-label">分类说明</label>
                <div class="layui-input-block">
                    <textarea name="remark" placeholder="请输入内容" class="layui-textarea"></textarea>
                </div>
            </div>

            <div class="layui-form-item" >
                <div class="layui-input-block">
                    <button id ='submit' style=" margin-left: 30%;" class="layui-btn" lay-submit="" lay-filter="add_article_type">新增</button>
                </div>
            </div>
        </form>
    </div>


{include file="public/footer"  /}


<script>
    layui.use(['form', 'layer'], function(){
              var form = layui.form
                   ,$ = layui.jquery
                   ,layer = layui.layer;
        //自定义验证规则
        form.verify({
            title: function(value){
                if(value.length <= 0){
                    return '分类名称不能为空';
                }
            }
        });


        //监听提交
        form.on('submit(add_article_type)', function(data){
            //调用新增菜单的方法
            add_article_type($,data.field,layer);
             return false;
        });
    });


    /**
     * 新增文章分类
     * @param $
     * @param data
     * @param layer
     */
     function  add_article_type($,data,layer) {
        var index = layer.msg('新增文章分类，请稍候',{icon: 16,time:false,shade:0.8});
          $.post("{:url('Articletype/add')}",data,function (res) {
              if(res.code==1){
                  layer.close(index);
                  layer.msg(res.msg,{
                      time:2000,
                      icon:1
                  },function () {
                      layer.closeAll('iframe');
                      parent.location.reload();
                  });
              }else{
                  layer.close(index);
                  layer.msg(res.msg,{
                      time:2000,
                      icon:2
                  });
              }
          });
     }
</script>


</body>
</html>